package com.design_mode;

/**
 * Created by dustaple on 2014/7/30.
 */
abstract class AbstractFactorys {

    public abstract <T extends Person> T getPerson(Class<T> c);
}

@SuppressWarnings("unchecked")
public class FactoryPattern extends AbstractFactorys {

    @Override
    public <T extends Person> T getPerson(Class<T> c) {
        Person person = null;
        try {
            person = (Person) Class.forName(c.getName()).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (T) person;
    }
}

abstract class Person {
    boolean gender;

    public abstract String say();
}

class Male extends Person {
    public Male() {
        gender = true;
    }

    @Override
    public String say() {
        return "I'm a man, I'm strong!";
    }
}

class Female extends Person {
    public Female() {
        gender = false;
    }

    @Override
    public String say() {
        return "I'm a girl, I'm thin!";
    }
}

